using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ContentOverContainer.Common;
using ContentOverContainer.Common.Converter;
using Roslyn.Compilers.CSharp;
using Roslyn.Services;

namespace ContentOverContainer
{
    /// <summary>
    /// Builds a list of nodes casted to a Multiplicity and a list of their references.
    /// //R-MCast1
    /// var anyToOptionCast = (OptionAttribute)m_AAny;
    /// //R-MCast2
    /// var anyToAnyCast = (AnyAttribute)(List<>)m_AAny;
    /// </summary>
    /// <author>Harald Binkle</author>
    public class CastExprWalker : BaseWalker
    {
        public CastExprWalker(ISolution pSolution, ReferencesList pReferences, ChangeNodeInfoList pChangeNodePairs) : base(pSolution, pReferences, pChangeNodePairs)
        {
        }

        public override void VisitCastExpression(CastExpressionSyntax node)
        {
            base.VisitCastExpression(node);


            CastExpressionSyntax syntaxNode = node;
            if (syntaxNode == null) return;

            var typeInfo = node.GetTypeInfo(m_SemModel);

            if (AnyAttribute.EqualsName(typeInfo.Name)|| OptionAttribute.EqualsName(typeInfo.Name))
            {
                var multiInfo = new MultiplicityInfo();
                m_References.Add(new NodeTypeInfo(node, multiInfo, Document));
            }           
        }

    }
}
